import { generateNanoid } from '@utils/nanoid'
import { createDotProp } from '@utils/editor-props'
/**
 * @description 创建编辑器配置
 * @returns {} 返回编辑器注册组件的方法等
 */
 export function createEditorConfig() {
    const componentModules = {
      base: [],
      container: [],
      custom: [],
    }
    // const componentList: VisualEditorComponent[] = []
    const componentMap = {}
    return {
      componentModules,
      componentMap,
      registry: (moduleName,key, component) => {
        const comp = { ...component, key, moduleName }
        componentModules[moduleName].push(comp)
        componentMap[key] = comp
      },
    }
  }

  export function createNewBlock(component) {
    return {
      uuid: `uuid_${generateNanoid()}`,
      moduleName: component.moduleName,
      componentKey: component.key,
      label: component.label,
      adjustPosition: true,
      focus: false,
      styles: {
        display: 'flex',
        justifyContent: 'flex-start',
        paddingTop: '0',
        paddingRight: '0',
        paddingLeft: '0',
        paddingBottom: '0',
        tempPadding: '0'
      },
      hasResize: false,
      props: Object.keys(component.props || {}).reduce((prev, curr) => {
        const { propObj, prop } = createDotProp(prev, curr)
        // if (component.props[curr]?.defaultValue) {
          propObj[prop] = prev[curr] = component.props[curr]?.defaultValue
        // }
        return prev
      }, {}),
      draggable: component.draggable ?? true, // 是否可以拖拽
      showStyleConfig: component.showStyleConfig ?? true, // 是否显示组件样式配置
      animations: [], // 动画集
      actions: [], // 动作集合
      events: component.events || [], // 事件集合
      model: {}
    }
  }